package com.ruoyi.web.controller.part;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PartType;
import com.ruoyi.system.service.IPartTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 停车场类型Controller
 * 
 * @author ruoyi
 * @date 2023-11-27
 */
@Controller
@RequestMapping("/part/type")
public class PartTypeController extends BaseController
{
    private String prefix = "part/type";

    @Autowired
    private IPartTypeService partTypeService;

    @RequiresPermissions("system:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询停车场类型列表
     */
    @RequiresPermissions("system:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PartType partType)
    {
        startPage();
        List<PartType> list = partTypeService.selectPartTypeList(partType);
        return getDataTable(list);
    }

    /**
     * 导出停车场类型列表
     */
    @RequiresPermissions("system:type:export")
    @Log(title = "停车场类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PartType partType)
    {
        List<PartType> list = partTypeService.selectPartTypeList(partType);
        ExcelUtil<PartType> util = new ExcelUtil<PartType>(PartType.class);
        return util.exportExcel(list, "停车场类型数据");
    }

    /**
     * 新增停车场类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存停车场类型
     */
    @RequiresPermissions("system:type:add")
    @Log(title = "停车场类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PartType partType)
    {
        return toAjax(partTypeService.insertPartType(partType));
    }

    /**
     * 修改停车场类型
     */
    @RequiresPermissions("system:type:edit")
    @GetMapping("/edit/{partTypeId}")
    public String edit(@PathVariable("partTypeId") Long partTypeId, ModelMap mmap)
    {
        PartType partType = partTypeService.selectPartTypeByPartTypeId(partTypeId);
        mmap.put("partType", partType);
        return prefix + "/edit";
    }

    /**
     * 修改保存停车场类型
     */
    @RequiresPermissions("system:type:edit")
    @Log(title = "停车场类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PartType partType)
    {
        return toAjax(partTypeService.updatePartType(partType));
    }

    /**
     * 删除停车场类型
     */
    @RequiresPermissions("system:type:remove")
    @Log(title = "停车场类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(partTypeService.deletePartTypeByPartTypeIds(ids));
    }
}
